package com.collect.cameroon.zhiScene.zhiRemind.zhiRecall;

import android.annotation.SuppressLint;
import android.app.Activity;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.collect.cameroon.R;
import com.collect.cameroon.zhiAdater.zhiRecall.ZHIRecallMarkedAdjuster;
import com.collect.cameroon.zhiBase.BaseFragment;
import com.collect.cameroon.zhiBean.zhiReceive.ZHIRMarkedCustomerFollowUserListEntity;
import com.collect.cameroon.zhiBean.zhiReceive.ZHIRWaitCustomerFollowUserListEntity;

import java.util.ArrayList;

import butterknife.BindView;

@SuppressLint("NonConstantResourceId")
public class ZHIRecallMarkedFragment extends BaseFragment<ZHIRecallPresenter> implements ZHIRecallContract.View {

    @BindView(R.id.tv_page_title)
    TextView tv_page_title;

    @BindView(R.id.srl_swipe_layout)
    SwipeRefreshLayout srl_swipe_layout;

    @BindView(R.id.tv_query_count)
    TextView tv_query_count;

    @BindView(R.id.rc_list)
    RecyclerView rc_list;

    ZHIRecallMarkedAdjuster mZHIRecallMarkedAdjuster = new ZHIRecallMarkedAdjuster();

    @Override
    protected void initInjector() {
        mFragmentComponent.inject(this);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_recall_marked;
    }

    @Override
    protected void initView(View view) {
        try {
            srl_swipe_layout.setColorSchemeColors(getResources().getColor(R.color.theme_color_0));
            initEvent();
            initData();

        }catch (Exception e){
            e.printStackTrace();
        }
    }

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
    }

    @Override
    public void onResume() {
        super.onResume();
    }

    @Override
    public void onGetErrorInfo() {
        srl_swipe_layout.setRefreshing(false);
    }

    @Override
    public void onGetLatestWaitCustomerFollowUserListV2(ArrayList<ZHIRWaitCustomerFollowUserListEntity> zhirWaitCustomerFollowUserListEntityArrayList) {

    }

    @SuppressLint("SetTextI18n")
    @Override
    public void onGetLatestMarkedCustomerFollowUserList(ArrayList<ZHIRMarkedCustomerFollowUserListEntity> zhirMarkedCustomerFollowUserListEntities) {
        try {
            srl_swipe_layout.setRefreshing(false);
            mZHIRecallMarkedAdjuster.setNewData(zhirMarkedCustomerFollowUserListEntities);
            tv_page_title.setText(getString(R.string.tab_marked)+"("+zhirMarkedCustomerFollowUserListEntities.size()+")");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public void onMarkCustomerFollowUser() {

    }

    @SuppressLint("InflateParams")
    public void initEvent() {
        srl_swipe_layout.setOnRefreshListener(this::initData);
        mZHIRecallMarkedAdjuster.setEmptyView(getRefreshEmptyView());
        rc_list.setLayoutManager(new GridLayoutManager(this.getActivity(), 1));
        rc_list.setAdapter(mZHIRecallMarkedAdjuster);
    }

    private void initData() {
        if (mPresenter != null) {
            mPresenter.getLatestMarkedCustomerFollowUserList(getActivity(), true);
        }
    }

    public void showQueryCountDialog() {

    }

    private View getRefreshEmptyView() {
        View emptyView = getLayoutInflater().inflate(R.layout.view_empty_no_data, null);
        emptyView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
        emptyView.setOnClickListener(v -> {
            initData();
        });
        return emptyView;
    }
}